package org.gesplan.entity;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Roger
 */
@Entity
@Table(name = "material")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Material.findAll", query = "SELECT m FROM Material m"),
    @NamedQuery(name = "Material.findById", query = "SELECT m FROM Material m WHERE m.id = :id"),
    @NamedQuery(name = "Material.findByDescription", query = "SELECT m FROM Material m WHERE m.description = :description"),
    @NamedQuery(name = "Material.findByPvp", query = "SELECT m FROM Material m WHERE m.pvp = :pvp"),
    @NamedQuery(name = "Material.findByPriceSupplier", query = "SELECT m FROM Material m WHERE m.priceSupplier = :priceSupplier"),
    @NamedQuery(name = "Material.findByIva", query = "SELECT m FROM Material m WHERE m.iva = :iva"),
    @NamedQuery(name = "Material.findByUnits", query = "SELECT m FROM Material m WHERE m.units = :units"),
    @NamedQuery(name = "Material.findByDatePvp", query = "SELECT m FROM Material m WHERE m.datePvp = :datePvp"),
    @NamedQuery(name = "Material.findBySupplierId", query = "SELECT m FROM Material m WHERE m.supplierId = :supplierId"),
})
public class Material implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private String id;
    @Basic(optional = false)
    @Column(name = "description")
    private String description;
    @Column(name = "pvp")
    private Float pvp;
    @Column(name = "price_supplier")
    private Float priceSupplier;
    @Column(name = "iva")
    private Float iva;
    @Column(name = "units")
    private String units;
    @Column(name = "date_pvp")
    @Temporal(TemporalType.DATE)
    private Date datePvp;
    @JoinColumn(name = "supplier_id", referencedColumnName = "id")
    @ManyToOne    
    private Supplier supplierId;
    @Column(name = "comments")
    private String comments;
    @JoinColumn(name = "material_family_id", referencedColumnName = "id")
    @ManyToOne
    private MaterialFamily materialFamilyId;

    
    public Material() { }

    public Material(String id) {
        this.id = id;
    }

    public Material(String id, String description) {
        this.id = id;
        this.description = description;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        String oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        String oldDescription = this.description;
        this.description = description;
        changeSupport.firePropertyChange("description", oldDescription, description);
    }

    public Float getPvp() {
        return pvp;
    }

    public void setPvp(Float pvp) {
        Float oldPvp = this.pvp;
        this.pvp = pvp;
        changeSupport.firePropertyChange("pvp", oldPvp, pvp);
    }

    public Float getPriceSupplier() {
        return priceSupplier;
    }

    public void setPriceSupplier(Float priceSupplier) {
        Float oldPriceSupplier = this.priceSupplier;
        this.priceSupplier = priceSupplier;
        changeSupport.firePropertyChange("priceSupplier", oldPriceSupplier, priceSupplier);
    }

    public Float getIva() {
        return iva;
    }

    public void setIva(Float iva) {
        Float oldIva = this.iva;
        this.iva = iva;
        changeSupport.firePropertyChange("iva", oldIva, iva);
    }

    public String getUnits() {
        return units;
    }

    public void setUnits(String units) {
        String oldUnits = this.units;
        this.units = units;
        changeSupport.firePropertyChange("units", oldUnits, units);
    }

    public Date getDatePvp() {
        return datePvp;
    }

    public void setDatePvp(Date datePvp) {
        Date oldDatePvp = this.datePvp;
        this.datePvp = datePvp;
        changeSupport.firePropertyChange("datePvp", oldDatePvp, datePvp);
    }

    public Supplier getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(Supplier supplierId) {
        Supplier oldSupplierId = this.supplierId;
        this.supplierId = supplierId;
        changeSupport.firePropertyChange("supplierId", oldSupplierId, supplierId);
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        String oldComments = this.comments;
        this.comments = comments;
        changeSupport.firePropertyChange("comments", oldComments, comments);
    }

    public MaterialFamily getMaterialFamilyId() {
        return materialFamilyId;
    }

    public void setMaterialFamilyId(MaterialFamily materialFamilyId) {
        MaterialFamily oldMaterialFamilyId = this.materialFamilyId;
        this.materialFamilyId = materialFamilyId;
        changeSupport.firePropertyChange("materialFamilyId", oldMaterialFamilyId, materialFamilyId);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Material)) {
            return false;
        }
        Material other = (Material) object;
        return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
    }

    @Override
    public String toString() {
        return id + " - " + description; 
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
    
}